//
//  AppDelegate.m
//  NewHalfsugar
//
//  Created by 刘志武 on 15/12/31.
//  Copyright © 2015年 刘志武. All rights reserved.
//

#import "AppDelegate.h"

#import "LzwHomeViewController.h"
#import "LzwAddViewController.h"
#import "LzwCameraViewController.h"
#import "LzwBellViewController.h"
#import "LzwUserViewController.h"
#import "LzwSingleton.h"
#import "UMSocial.h"
#import "LzwStartOverPageVC.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //设置友盟分享key
    [UMSocialData setAppKey:@"56911ce367e58e117a002ed8"];
    
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //打开数据库
    [[LzwSingleton shareDataBase] openDB];
    [[LzwSingleton shareDataBase] createTable];
    [[LzwSingleton shareDataBase] createNewBetweenTable];
    [[LzwSingleton shareDataBase] createNewFootTable];
    [[LzwSingleton shareDataBase] createAttentionTable];
//    [[LzwSingleton shareDataBase]createNewAdressHeadTable];
//    [[LzwSingleton shareDataBase]createNewAdressFootTable];
    [[LzwSingleton shareDataBase] creatBellTable];
    
    LzwHomeViewController *home = [[LzwHomeViewController alloc]init];
    LzwAddViewController *address = [[LzwAddViewController alloc]init];
    LzwCameraViewController *camera = [[LzwCameraViewController alloc]init];
    LzwBellViewController *bell = [[LzwBellViewController alloc]init];
    LzwUserViewController *user = [[LzwUserViewController alloc]init];
    
    //创建导航控制器
    UINavigationController *homeVc = [[UINavigationController alloc]initWithRootViewController:home];
    [homeVc.navigationBar setBackgroundColor:[UIColor redColor]];
    homeVc.navigationBar.translucent = NO;
    
    [homeVc.navigationBar setBackgroundImage:[UIImage imageNamed:@"pink.png"] forBarMetrics:UIBarMetricsDefault];
    
    homeVc.tabBarItem = [[UITabBarItem alloc]initWithTitle:nil image: [UIImage imageNamed:@"13.png"] selectedImage:nil];
    
    UINavigationController *addressVc = [[UINavigationController alloc]initWithRootViewController:address];
    addressVc.navigationBar.translucent = NO;
    [addressVc.navigationBar setBackgroundImage:[UIImage imageNamed:@"pink.png"] forBarMetrics:UIBarMetricsDefault];
    addressVc.tabBarItem = [[UITabBarItem alloc]initWithTitle:nil image:[UIImage imageNamed:@"2.png"] selectedImage:nil];
    
    UINavigationController *cameraVc = [[UINavigationController alloc]initWithRootViewController:camera];
    cameraVc.navigationBar.translucent = NO;
    
    UIImage *image = [UIImage imageNamed:@"red.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    cameraVc.tabBarItem = [[UITabBarItem alloc]initWithTitle:nil image:image selectedImage:nil];
    
    UINavigationController *bellVc = [[UINavigationController alloc]initWithRootViewController:bell];
    bellVc.navigationBar.translucent = NO;
        [bellVc.navigationBar setBackgroundImage:[UIImage imageNamed:@"pink.png"] forBarMetrics:UIBarMetricsDefault];
    bellVc.tabBarItem = [[UITabBarItem alloc]initWithTitle:nil image:[UIImage imageNamed:@"4.png"] selectedImage:nil];
    
    UINavigationController *userVc = [[UINavigationController alloc]initWithRootViewController:user];
    userVc.navigationBar.translucent = NO;
    [userVc.navigationBar setBackgroundImage:[UIImage imageNamed:@"pink.png"] forBarMetrics:UIBarMetricsDefault];
    user.tabBarItem = [[UITabBarItem alloc]initWithTitle:nil image:[UIImage imageNamed:@"5.png"] selectedImage:nil];
    
    
    //创建标签控制器
    UITabBarController *TabBarC = [[UITabBarController alloc]init];
    
    TabBarC.viewControllers = [NSArray arrayWithObjects:homeVc, addressVc, bellVc, userVc, nil];
    //设置bar的背景颜色
    TabBarC.tabBar.backgroundColor = [UIColor yellowColor];
    //设置bar的选中颜色
    TabBarC.tabBar.tintColor = [UIColor redColor];
    //协议代理
    TabBarC.delegate = self;
    
    self.window.rootViewController = TabBarC;
    
    LzwStartOverPageVC *starVC = [[LzwStartOverPageVC alloc]init];
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"star"] == nil) {
        [self.window.rootViewController presentViewController:starVC animated:NO completion:^{
            
            
        }];
        [[NSUserDefaults standardUserDefaults] setObject:@"Comeon" forKey:@"star"];
    }
    
    
    [home release];
    [bell release];
    [camera release];
    [address release];
    [user release];
    [_window release];
    
    

    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
